//
//  TipsProjectTests.m
//  TipsProjectTests
//
//  Created by Suny on 15/4/29.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "UserService.h"
#import "TopicInfoService.h"
#import "TopicInfo.h"
@interface TipsProjectTests : XCTestCase

@end

@implementation TipsProjectTests

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testExample {
    // This is an example of a functional test case.
    XCTAssert(YES, @"Pass");
	
}


- (void)testModifyPassword 
{
	// This is an example of a functional test case.
	XCTAssert(YES, @"Pass");
	UserInfo *user = [UserInfo new];
	user.userId = @"12";
	
	[[UserService serviceWithDefaultBaseUrlString] modifyPassword:user
													  newPassword:@"111111"
												  withFinishBlock:^(BaseResponse *response) {
													  DLogObject(response); 
													  
													  CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
													  CFRunLoopStop(runLoopRef); 
												  }];
	
	CFRunLoopRun();
}

- (void)testUpLoadImage
{
	AFHTTPRequestSerializer *serialize = [AFHTTPRequestSerializer serializer];
	UserInfo *user = [UserInfo new];
	user.loginName = @"123@12312.com";
	user.password = @"1234567";
	user.age = @"12";
	user.nickName = @"43";
	user.sex = @"男";
	
	NSDictionary *dic = [user dictionaryWithNameAndValue];
	
	 
	NSURLRequest *request = [serialize multipartFormRequestWithMethod:@"POST"
															URLString:@"http://182.92.99.17:8080/mimoo/api/member/upload/"
														   parameters:dic
											constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
												[formData appendPartWithFileData:UIImageJPEGRepresentation([UIImage imageNamed:@"app_icon"], 1) 
																			name:@"123"
																		fileName:@"123.jpg" 
																		mimeType:@"image/jpeg"];
											} error:nil];
	
	AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
	[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
		DLogObject(responseObject); 
		
		CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
		CFRunLoopStop(runLoopRef); 
	} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
		DLogObject(error); 
		
		CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
		CFRunLoopStop(runLoopRef); 
	}];
	[requestOperation start];
	CFRunLoopRun();

}

- (void)testGetTopic
{
	[[TopicInfoService serviceWithDefaultBaseUrlString] getTopicListWithFinishBlock:^(BaseResponse *response) {
		
		
		NSMutableArray *objectArray = [NSMutableArray array];
		for (NSDictionary * dic in response.object) 
		{
			TopicInfo *info = [[TopicInfo alloc] initWithSourceString:dic];
			[objectArray addObject:info];
		}

		DLogObject(objectArray); 
		
		
		
		CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
		CFRunLoopStop(runLoopRef); 
	}];
	
	CFRunLoopRun();

}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
